package com.example.messagemodule.ui;

import android.graphics.Color;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.examination.mlib.constants.ARouterConstants;
import com.examination.mlib.constants.AllStringConstants;
import com.example.messagemodule.R;
import com.example.messagemodule.entity.DirectionUsingMedicineDetailEntity;
import com.google.gson.Gson;
import com.examination.mlib.baseold.ModuleBaseActivity;
import com.examination.mlib.interfaceapi.NetWorkCallBack;
import com.yilijk.base.network.RequestParams;
import com.yilijk.base.network.https.HttpCallBack;
import com.yilijk.base.network.https.HttpUtils;
import com.yilijk.base.network.https.interceptor.NetWorkUtils;
import com.yilijk.base.utils.ClickUtils;
import com.yilijk.base.utils.DataUtils;
import com.yilijk.base.utils.DevicesUtils;
import com.yilijk.base.utils.LoadingUtils;
import com.zzhoujay.richtext.RichText;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.ParseException;
import java.util.Date;
import crossoverone.statuslib.StatusUtil;

@Route(path = ARouterConstants.DirectionUsingMedicineDetailActivity)
public class DirectionUsingMedicineDetailActivity extends ModuleBaseActivity {

    private Handler handler = new Handler();

    private ImageView directionUsingMedicineDetailActivityBack;
    private TextView directionUsingMedicineDetailActivityTitle;
    private TextView directionUsingMedicineDetailActivityFrom;
    private TextView directionUsingMedicineDetailActivityContent;
    private TextView directionUsingMedicineDetailActivityTime;

    @Autowired
    long commonId;

    @Override
    public int bondLayout() {
        return R.layout.activity_direction_using_medicine_detail;
    }

    @Override
    public void initView() {
        StatusUtil.setUseStatusBarColor(this, Color.WHITE);
        StatusUtil.setSystemStatus(this, false, true);

        directionUsingMedicineDetailActivityBack = (ImageView) findViewById(R.id.directionUsingMedicineDetailActivity_back);
        directionUsingMedicineDetailActivityTitle = (TextView) findViewById(R.id.directionUsingMedicineDetailActivity_title);
        directionUsingMedicineDetailActivityFrom = (TextView) findViewById(R.id.directionUsingMedicineDetailActivity_from);
        directionUsingMedicineDetailActivityContent = (TextView) findViewById(R.id.directionUsingMedicineDetailActivity_content);
        directionUsingMedicineDetailActivityTime = (TextView) findViewById(R.id.directionUsingMedicineDetailActivity_time);

    }

    @Override
    public void initData() {
        LoadingUtils.getLoadingUtils(this).showLoading();
        RequestParams jsonObject = new RequestParams();
        jsonObject.put("commonId",commonId);

        HttpUtils.get(AllStringConstants.MessageUrl.commonGet, jsonObject, new HttpCallBack<DirectionUsingMedicineDetailEntity>() {
            @Override
            public void onSuccess(DirectionUsingMedicineDetailEntity directionUsingMedicineDetailEntity, int i) {
                if (directionUsingMedicineDetailEntity.isResult() && directionUsingMedicineDetailEntity.getData()!=null){
                    DirectionUsingMedicineDetailEntity.DataBean data = directionUsingMedicineDetailEntity.getData();
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            if (data.getCommonTitle()!=null){
                                directionUsingMedicineDetailActivityTitle.setText(data.getCommonTitle());
                            }

                            if (data.getCreateUser()!=0){
                                directionUsingMedicineDetailActivityFrom.setText("来源： "+data.getSource());
                            }

                            if (data.getDetail()!=null){
                                RichText.fromHtml(data.getDetail()).bind(this)
                                        .showBorder(false)
                                        .into(directionUsingMedicineDetailActivityContent);
                            }
                            if (data.getCreateTime()!=0){
                                String s = DataUtils.long2string(data.getCreateTime(), "yyyy-MM-dd");
                                directionUsingMedicineDetailActivityTime.setText("发表于"+s);
                            }


                        }
                    });
                }
                LoadingUtils.getLoadingUtils(DirectionUsingMedicineDetailActivity.this).dismissLoading();
            }

            @Override
            public void onFailure(String s, int i) {
                LoadingUtils.getLoadingUtils(DirectionUsingMedicineDetailActivity.this).dismissLoading();

            }
        });


    }

    @Override
    public void initEvent() {
        ClickUtils.setFastOnClickListener(directionUsingMedicineDetailActivityBack, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


}